<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class CollageMember extends Model
{
    public function user()
    {
        return $this->belongsTo('Users','user_id')->bind(['nickname','avator']);
    }

    public function collage()
    {
        return $this->belongsTo('Collage','collage_id');
    }

    public function collageMemberInfo($where)
    {
        return self::where($where)->find();
    }

    public function joinMember($data)
    {
        return self::create($data);
    }

    public function memberNum($collage_id)
    {
        return self::where('collage_id',$collage_id)->count();
    }

    public function collageList($collage_id)
    {
        return self::with(['user'])->where('collage_id',$collage_id)->order('surplus_people_num','desc')->select()->toArray();
    }
}
